﻿using System.Reflection;
using ApiConceptsFramework.FluentApi;
using ZipApiExample.Api2;
using NUnit.Framework;

namespace test.ApiConceptsFramework.FluentApi.Scenarios
{
	[TestFixture, Explicit]
	public class ZipApi2Tests
	{
		private Assembly[] _assemblies;
		private string[] _usings;
		private ApiEvaluator _eval;

		#region Setup
		[SetUp]
		public void SetUp()
		{
			_assemblies = new[] { typeof(ZipFile).Assembly };
			_usings = new[] { "ZipApiExample.Api2" };

			_eval = new ApiEvaluator(_assemblies);
			_eval.SetUsings(_usings);
			_eval.SetAssemblyRefs(_assemblies);
		}

		[TearDown]
		public void TearDown()
		{
			_eval.EvaluateAndPrintToConsole();
		}
		#endregion

		[Test]
		public void Zip_Single_File()
		{
			int prevUsages = 0;
			//using (ZipFile zip = ZipFile.CreateNew("filename"))
			//{
			//	zip.AddFile(fileToZip);
			//	zip.Save(zippedFile);
			//}
			//_eval.ClassUsage<ZipFile>();
			_eval.MethodCall((ZipFile z) => ZipFile.CreateNew("filename"), previousUsages: prevUsages);
			_eval.MethodCall((ZipFile z) => z.AddFile("filename"), returnParameterIsUsed: false, previousUsages: prevUsages);
			_eval.MethodCall((ZipFile z) => z.Save(), previousUsages: prevUsages);
		}

		[Test]
		public void Unzip_All_Files()
		{
			//using (ZipFile zip = ZipFile.Read(zippedFile))
			//{
			//	zip.ExtractAll(unzipPath);
			//}
			//_eval.ClassUsage<ZipFile>(1,1);
			_eval.MethodCall((ZipFile z) => ZipFile.Read("filename"));
			_eval.MethodCall((ZipFile z) => z.ExtractAll("unzipPath"));
		}

		[Test]
		public void Update_Zip_Content()
		{
			//using (ZipFile zip = ZipFile.Read(zippedFile))
			//{
			//	zip.UpdateEntry(fileToUpdate, contentToUpdate, null, UpdateAction.Overwrite);
			//	zip.Save();
			//}
			//_eval.ClassUsage<ZipFile>(1,2);
			_eval.MethodCall((ZipFile z) => ZipFile.Read("filename"),1,2);
			_eval.MethodCall((ZipFile z) => z.UpdateEntry("fileToUpdate", "contentToUpdate", null, UpdateAction.Overwrite), returnParameterIsUsed: false);
			_eval.MethodCall((ZipFile z) => z.Save(),1,1);
		}

		[Test]
		public void Remove_File_From_Zip()
		{
			//using (ZipFile zip = ZipFile.Read(zippedFile))
			//{
			//	zip.RemoveEntry(fileToRemove);
			//	zip.Save();
			//}
			//_eval.ClassUsage<ZipFile>(1,3);
			_eval.MethodCall((ZipFile z) => ZipFile.Read("filename"),1,3);
			_eval.MethodCall((ZipFile z) => z.RemoveEntry("filename"));
			_eval.MethodCall((ZipFile z) => z.Save(),1,2);
		}

		[Test]
		public void Zip_Single_File_With_Password()
		{
			//using (ZipFile zip = ZipFile.CreateNew("filename"))
			//{
			//	zip.SetPassword("password");
			//	zip.AddFile(fileToZip);
			//	zip.Save(zippedFile);
			//}
			//_eval.ClassUsage<ZipFile>(1,4);
			_eval.MethodCall((ZipFile z) => ZipFile.CreateNew("filename"),1,2);
			_eval.MethodCall((ZipFile z) => z.SetPassword("pw"));
			_eval.MethodCall((ZipFile z) => z.AddFile("filename"), 1, 2, returnParameterIsUsed: false);
			_eval.MethodCall((ZipFile z) => z.Save(), 1, 3);
		}
	}
}